package com.ruoyi.project.storage.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.common.enums.OrderOpreate;
import com.ruoyi.project.storage.domain.vo.OrderVO;
import com.ruoyi.project.storage.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * App端我的订单Controller
 *
 * @author mengyuanqing
 * @date 2020/5/15
 */
@RestController
@RequestMapping("app/order")
@Api(tags = {"【手机端】5.2.4 我的订单"},description = "订单列表（分页）、订单详情、订单操作")
public class AppOrderController extends BaseController {
    // 通过注解注入
    @Autowired
    private IOrderService orderService;
    /**
     * 查询手机端当前客户订单
     *
     * @return 结果
     */
    @Log(title = "5.2.4.1 订单列表（分页）", businessType = BusinessType.OTHER)
    @GetMapping("/list")
    @ApiOperation(value = "5.2.4.1 订单列表（分页）", notes = "查询订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", dataType = "int", value = "当前页数", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", dataType = "int", value = "每页显示记录数", defaultValue = "10")
    })
    public TableDataInfo list(OrderVO orderVO) {
        // 获取分页信息
        startPage();
        // 只查询我当前id下
        orderVO.setUserId(SecurityUtils.getUserId());
        // 查询广告列表
        List<OrderVO> list = orderService.selectOrderList(orderVO);
        // 返回一个响应请求分页数据
        return getDataTable(list);
    }
    /**
     * 订单详情
     */
    @Log(title = "5.2.4.2 订单详情", businessType = BusinessType.OTHER)
    @GetMapping("/info/{id}")
    @ApiOperation(value = "5.2.4.2 订单详情", notes = "订单详情")
    public AjaxResult list(@PathVariable Long id) {
        // 实例化
        OrderVO orderVO =new OrderVO();
        // 设置要查询的订单id
        orderVO.setId(id);
        // 设置当前用户
        orderVO.setUserId(SecurityUtils.getUserId());
        // 返回成功消息
        AjaxResult ajax =AjaxResult.success();
        // 把订单详情放入map
        ajax.put("data",orderService.selectOrder(orderVO));
        //返回响应结果
        return ajax;
    }
    /**
     * 订单操作
     */
    @Log(title = "5.3.6.3 订单操作", businessType = BusinessType.OTHER)
    @PutMapping("/operate/{id}/{status}/{version}")
    @ApiOperation(value = "5.2.4.3 订单操作", notes = "订单操作")
    public AjaxResult operate(@PathVariable Long id,@PathVariable Integer status,@PathVariable Long version,@RequestBody OrderVO orderVO) {
        // 返回响应结果
        return toAjax(orderService.updateOperate(OrderOpreate.getoperate("app",status),id,status,version,orderVO));
    }
}
